<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>借出资产</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/iconfont.css">
    <link rel="stylesheet" href="../../css/base.css">
    <script src="../../js/jquery-1.11.0.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../js/frameAll.js"></script>
    <style>
        .layui-form {
            margin-top: 30px;
        }
    </style>

</head>
<body>
<form class="layui-form" lay-filter="infoForm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">资产名称 : </label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="zcName" autocomplete="off" class="layui-input"
                       placeholder="请输入要查询的名称">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="submitBut">查询</button>
        </div>
    </div>
</form>
<table id="info" lay-filter="out"></table>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table,
            form = layui.form;
        var info = {zcName: ''};
        //数据表格
        var tableIns = table.render({
            elem: '#info',
            height: 'full-128',
            url: '/fixedAsset/zc/overPage.do',
            cellMinWidth: '100',
            text: {
                none: 'QAQ没有查到数据，换个条件吧'
            },
            where: info,
            request: {
                pageName: 'pageNo',
                limitName: 'pageSize'
            },
            page: true,
            cols: [[
                {title: '序号', type: 'numbers', width: 80},
                {field: 'zcName', title: '资产名称', unresize: true},
                {field: 'zcState', title: '状态', unresize: true},
                {title: '操作', align: "center", toolbar: '#barDemo', unresize: true}
            ]],
            error: function () {
                top.location.href = "../../login.html";
            },
            done: function (res) {
                if (res.message) {
                    noMsg(res.message);
                }
            },
        });
        //查询指定条件的用户
        form.on('submit(submitBut)', function (data) {
            var field = data.field;
            info.zcName = field.zcName;
            tableIns.reload({
                page: {curr: 1}
            });
            return false;
        });
        //借出
        table.on('tool(out)', function (obj) {
            var data = obj.data
                , layEvent = obj.event;
            if (layEvent === 'out') {
                layer.open({
                    type: 2,
                    title: '借出资产',
                    area: ['380px', '94%'],
                    resize: false,
                    offset: '3%',
                    btn: ["提交", "取消"],
                    btnAlign: 'c',
                    scrollbar: false,
                    content: "addOut.html",
                    success: function (layero, index) {
                        $(layero).find("iframe")[0].contentWindow.setInfo(data);
                    },
                    yes: function (index, layero) {
                        //父页面调用子页面的函数获取返回值
                        var info = $(layero).find("iframe")[0].contentWindow.getInfo();
                        console.log(info);
                        if (!info.comployeeNo) {
                            noMsg('借用人不得为空');
                            return;
                        }
                        if (!info.shouldTime) {
                            noMsg('应还日期不得为空');
                            return;
                        }
                        $.ajax({
                            type: 'Post',
                            url: '/fixedAsset/inout/out.do',
                            data: info,
                            dataType: 'Json',
                            success: function (data) {
                                if (data.code === 0) {
                                    tableIns.reload({
                                        page: {curr: $(".layui-laypage-em").next().html()}
                                    });
                                    yesMsg(data.message);
                                    layer.close(index);
                                } else {
                                    noMsg(data.message);
                                }
                            }
                        });
                    }
                });
            }
        });
    });
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-bg-blue layui-btn-sm" lay-event="out">借出</a>
</script>
</body>
</html>